package parse

import (
	"awesomeProject2/src/test2020/util"
	"bytes"
	"github.com/PuerkitoBio/goquery"
	"io/ioutil"
)

type Context struct {
	Path     string
	HasParse bool
	Doc      *goquery.Document
}

func (c *Context) LoadFile(path string) {
	c.Path = path
}

func (c *Context) Parse() {
	if len(c.Path) > 0 {
		bt, _ := ioutil.ReadFile(c.Path)
		gbkBytes, _ := util.ToGBKBytes(bt)
		doc, err := goquery.NewDocumentFromReader(bytes.NewReader(gbkBytes))
		if err == nil {
			c.Doc = doc
		}
	}
}

func (c *Context) GetDoc() *goquery.Document {
	return c.Doc
}
